a = int(input())
if len(str(a))!=4 or a <= 0:
    print("0")
    exit()
t = a // 1000
sot = (a - t * 1000) // 100
des = a // 10 % 10
ed = a % 10
maxX=0
b = [t, sot, des, ed, t * 10 + sot, t * 100 + sot * 10 + des, a, sot * 10 + des, sot * 100 + des * 10 + ed, des * 10 + ed]
for i in range(len(b)):
    count = 0
    for c in range(2, b[i] // 2 + 1):
        if b[i] % c == 0:
            count += 1
    if count <= 0:
        if maxX < b[i]:
            maxX = b[i]
print(maxX)